import { IProvider } from '@/types'
import request from '@/utils/request'

export const getProviderList = () => {
  return request.get('/provider/get_all_providers')
}

export const getProviderById = (id: string) => {
  return request.get(`/provider/get_provider_by_id/${id}`)
}

export const addProvider = (data: IProvider) => {
  return request.post('/provider/add_provider', data)
}

export const updateProviderById = (data: IProvider) => {
  return request.post('/provider/update_provider', data)
}

export const deleteProvider = (id: string) => {
  return request.post('/provider/delete_provider', { id })
}

export const testConnection = (id: string) => {
  return request.post('/provider/connect_test', { id })
}

export const fetchModels = async (providerId: string) => {
  return await request.get('/model/model_list/' + providerId)
}

export const fetchEnableModelById = async (id: string) => {
  return await request.get('/model/model_enable/' + id)
}

export async function addModel(data: { provider_id: string; model_name: string }) {
  return request.post('/model/models', data)
}

export const fetchEnableModels = async () => {
  return await request.get('/model/model_list')
}

export const deleteModelById = async (modelId: number) => {
  return await request.get(`/model/models/delete/${modelId}`)
}